package com.czy.owner.adapter;

import android.content.Context;
import android.view.ViewGroup;

import com.czy.owner.entity.StoreActivityModel;
import com.czy.owner.ui.store.storeviewholder.StoreTvAndImgViewHolder;
import com.czy.owner.ui.store.storeviewholder.StoreTvAndVideoViewHolder;
import com.czy.owner.ui.store.storeviewholder.StoreTvDefaultViewHolder;
import com.czy.owner.utils.MyLog;
import com.easyrecycleview.adapter.BaseViewHolder;
import com.easyrecycleview.adapter.RecyclerArrayAdapter;

/**
 * Created by wangyang on 2016/9/21.
 */
public class StoreAdapter extends RecyclerArrayAdapter<StoreActivityModel.StoreList> {
    public static final int TYPE_INVALID = 0;
    public static final int TYPE_TV_IMG = 1;
    public static final int TYPE_TV_VIDEO = 2;
    public static final String TYPE_TV_IMG_STRING = "pic";
    public static final String TYPE_TV_VIDEO_STRING = "video";
    private Context ctx;


    public StoreAdapter(Context context) {
        super(context);
        this.ctx = context;
    }

    @Override
    public int getViewType(int position) {
        return checkDataType(getItem(position));
    }

    private int checkDataType(StoreActivityModel.StoreList tm) {
        StringBuffer sbResType = new StringBuffer();
        for (int i = 0; i < tm.getResList().size(); i++) {
            sbResType.append(tm.getResList().get(i).getResType() + ",");
        }
        if (sbResType.toString().contains(TYPE_TV_IMG_STRING)) {
            return TYPE_TV_IMG;
        }
        if (sbResType.toString().contains(TYPE_TV_VIDEO_STRING)) {
            return TYPE_TV_VIDEO;
        }

        return TYPE_INVALID;
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        switch (viewType) {
            case TYPE_TV_IMG:
                return new StoreTvAndImgViewHolder(parent, ctx);
            case TYPE_TV_VIDEO:
                return new StoreTvAndVideoViewHolder(parent, ctx);
            default:
                return new StoreTvDefaultViewHolder(parent, ctx);
        }

    }
}
